home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
YICN23.ZIP
/
SOURCE
/
YEDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-16
|
3KB
|
142 lines
#include <stdio.h>
#include "xlib.h"
#include "xmouse.h"
#include "mouse.spr"
main(int argc,char *argv[])
{
int maxx;
int i,j,k;
int color = 1;
int ext = 0;
int w,h;
int x,y,b,v;
unsigned char bg = 0;
char fn[20],c;
FILE *fp;
unsigned char grid[16][16];
if(argc != 2) exit();
maxx = x_set_mode(3,376);
x_mouse_init();
strcpy(fn,argv[1]);
strcat(fn,".spr");
fp = fopen(fn,"r");
if(fp)
{
while((c = fgetc(fp))!= '{');
fscanf(fp,"%d,%d,",&w,&h);
}
for(i=0;i<4;i++)
{
for(j=0;j<16;j++)
{
for(k=0;k<4;k++)
{
if(fp)
{
fscanf(fp,"%d ,",&v);
grid[k*4+i][j] = v;
}
else
grid[k*4+i][j] = 0;
}
}
}
if(fp)
fclose(fp);
x_mouse_setim(mouse);
x_mouse_hide();
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
{
x_rect_fill(200+i*10,j*10,200+i*10+9,j*10+9,Page0_Offs,i*16+j);
x_rect_fill(i*10+2,j*10+2,i*10+9,j*10+9,Page0_Offs,grid[i][j]);
}
}
for(i=0;i<17;i++)
{
x_line(i*10,0,i*10,160,1,Page0_Offs);
x_line(0,i*10,160,i*10,1,Page0_Offs);
}
x_mouse_show();
while(!ext)
{
x_rect_fill(0,200,20,220,Page0_Offs,color);
while(!kbhit() && x_mouse_bstat == 0);
x = x_mouse_x;
y = x_mouse_y;
b = x_mouse_bstat;
if(x > 200 && x < 360 && y > 0 && y < 160)
{
if(b &1)
color = ((x - 200)/10)*16+(y/10);
else
bg = ((x - 200)/10)*16+(y/10);
}
else if(x < 160 && y < 160)
{
if(b & 1)
{
x_mouse_hide();
x_rect_fill(x/10*10+2,y/10*10+2,x/10*10+9,y/10*10+9,Page0_Offs,color);
x_mouse_show();
grid[x/10][y/10] = color;
}
else
{
x_mouse_hide();
x_rect_fill(x/10*10+2,y/10*10+2,x/10*10+9,y/10*10+9,Page0_Offs,0);
x_mouse_show();
grid[x/10][y/10] = 0;
}
}
else if(b & 0x02)
{
ext = 1;
}
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
{
if(grid[i][j])
x_put_pix(100+i,200+j,Page0_Offs,grid[i][j]);
else
x_put_pix(100+i,200+j,Page0_Offs,bg);
}
}
}
x_mouse_remove();
x_text_mode();
strcpy(fn,argv[1]);
strcat(fn,".spr");
fp = fopen(fn,"w");
fprintf(fp,"unsigned char %s[] = {\n\t4,16,\n\t",argv[1]);
for(i=0;i<4;i++)
{
for(j=0;j<16;j++)
{
for(k=0;k<4;k++)
{
fprintf(fp,"%d ",grid[k*4+i][j]);
if(k!=3 || j!=15 || i!=3)
fprintf(fp,",");
}
fprintf(fp,"\n\t");
}
}
fprintf(fp,"};");
fclose(fp);
}